//从数据中循环得到级联的回显
// @ts-ignore
export function GetFullParents(props: IParentItems): string[] {

    if (props.dataid != undefined && props.dataid != "" && props.items != undefined) {
        for (let i = 0; i < props.items.length; i++) {
            if (props.items[i][props.idName] == props.dataid) {
                if (!props.parentIds.includes(props.dataid)) {
                    props.parentIds.unshift(props.dataid);
                }
                if (props.items[i][props.parentIdName] != undefined && props.items[i][props.parentIdName] != "0") {
                    let subItem: IParentItems = {
                        parentIds: props.parentIds,
                        allItems: props.allItems,
                        items: props.allItems,
                        dataid: props.items[i][props.parentIdName],
                        idName: props.idName,
                        parentIdName: props.parentIdName,
                        haveRoot: props.haveRoot
                    }
                    GetFullParents(subItem);
                } else {
                    if (props.haveRoot && !props.parentIds.includes("0")) {
                        props.parentIds.unshift("0");
                    }
                }
            }

            if (props.items[i].children && props.items[i].children.length > 0) {
                let subItem: IParentItems = {
                    parentIds: props.parentIds,
                    allItems: props.allItems,
                    items: props.items[i].children,
                    dataid: props.dataid,
                    idName: props.idName,
                    parentIdName: props.parentIdName,
                    haveRoot: props.haveRoot
                }
                GetFullParents(subItem);
            }
        }
    }

    return props.parentIds;
}

//需要递归处理的参数
export interface IParentItems {
    //返回的父级ID
    parentIds: string[],
    //所有要处理的数据
    allItems: any[],
    //当前要处理的数据
    items: any[],
    //数据主键
    dataid?: string,
    //主键属性名
    idName: string,
    //父级属性名
    parentIdName: string,
    //是否包含根节点
    haveRoot?: boolean
}
